<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  <title>Matrix207&#39;s Blog</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta property="og:type" content="website">
<meta property="og:title" content="Matrix207's Blog">
<meta property="og:url" content="http://yoursite.com/page/4/index.html">
<meta property="og:site_name" content="Matrix207's Blog">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Matrix207's Blog">
  
    <link rel="alternate" href="/atom.xml" title="Matrix207&#39;s Blog" type="application/atom+xml">
  
  
    <link rel="icon" href="/favicon.png">
  
  
    <link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  
  <link rel="stylesheet" href="/css/style.css">
  

</head>

<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/" id="logo">Matrix207&#39;s Blog</a>
      </h1>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="/">Home</a>
        
          <a class="main-nav-link" href="/archives">Archives</a>
        
      </nav>
      <nav id="sub-nav">
        
          <a id="nav-rss-link" class="nav-icon" href="/atom.xml" title="Flux RSS"></a>
        
        <a id="nav-search-btn" class="nav-icon" title="Rechercher"></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" results="0" class="search-form-input" placeholder="Search"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="sitesearch" value="http://yoursite.com"></form>
      </div>
    </div>
  </div>
</header>
      <div class="outer">
        <section id="main">
  
    <article id="post-how-to-export-a-specify-full-directory-by-shell-file" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2015/09/10/how-to-export-a-specify-full-directory-by-shell-file/" class="article-date">
  <time datetime="2015-09-09T16:00:00.000Z" itemprop="datePublished">2015-09-10</time>
</a>
    
  <div class="article-category">
    <a class="article-category-link" href="/categories/language/">language</a>
  </div>

  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/2015/09/10/how-to-export-a-specify-full-directory-by-shell-file/">How to export a specify full directory by shell file</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h3 id="Requirement"><a href="#Requirement" class="headerlink" title="Requirement"></a>Requirement</h3><ul>
<li><p>project files</p>
<pre><code>myprj
    build
      env.sh
      Makefile
      submake
        MakeFlagTest1
        MakeFlagTest2
    doc
      readme.doc
    src
      a.h
      a.c
      b.h
      b.c
      main.c
    test
      test.c
</code></pre></li>
<li><p>In env.sh, need to export some environment variable, how to implement?<br>If add hard code, it will looks like : <code>export PRJ_HOME=/home/dennis/myprj</code></p>
</li>
<li><p>Using case</p>
<ul>
<li>cd /home/dennis; source myprj/build/env.sh</li>
<li>cd /home/dennis; source ./myprj/build/env.sh</li>
<li>cd /home/dennis; source ~/myprj/build/env.sh</li>
<li>cd /home/dennis/myprj/build; source env.sh</li>
<li>cd /home/dennis/myprj/build; source ./env.sh</li>
<li>cd /home/dennis/myUT/src; source ../../myprj/build/env.sh</li>
<li>cd /home/dennis/myUT/src; source ~/myprj/build/env.sh</li>
</ul>
</li>
</ul>
<h3 id="Test-1-using-export-PRJ-HOME-dirname-dirname-0"><a href="#Test-1-using-export-PRJ-HOME-dirname-dirname-0" class="headerlink" title="Test 1, using export PRJ_HOME=$(dirname $(dirname $0))"></a>Test 1, using <code>export PRJ_HOME=$(dirname $(dirname $0))</code></h3><ul>
<li>Failure case, when on suse release version, will failed to do <code>dirname $0</code>,<br>you will find that <code>echo $0</code> output <code>-bash</code>, not <code>bash</code> expected.</li>
</ul>
<h3 id="Test-2-using-export-PRJ-HOME-dirname-dirname-BASH-SOURCE-0"><a href="#Test-2-using-export-PRJ-HOME-dirname-dirname-BASH-SOURCE-0" class="headerlink" title="Test 2, using export PRJ_HOME=$(dirname $(dirname ${BASH_SOURCE[0]))"></a>Test 2, using <code>export PRJ_HOME=$(dirname $(dirname ${BASH_SOURCE[0]))</code></h3><ul>
<li>Failure case, when using relative directory.</li>
</ul>
<h3 id="Other-test"><a href="#Other-test" class="headerlink" title="Other test"></a>Other test</h3><pre><code>echo &quot;working directory is &quot; $(pwd)
echo &quot;BASH_SOURCE is &quot; ${BASH_SOURCE}
echo &quot;BASH_SOURCE[0] is &quot; ${BASH_SOURCE[0]}
echo &quot;dirname BASH_SOURCE[0] is &quot; $(dirname ${BASH_SOURCE[0]})
echo &quot;2 dirname BASH_SOURCE[0] is &quot; $(dirname $(dirname ${BASH_SOURCE[0]}))
PARENT_DIR=$(dirname $(dirname ${BASH_SOURCE[0]}))
echo &quot;parent dir is &quot; ${PARENT_DIR}
export GMDB_HOME=$(pwd ${PARENT_DIR})
</code></pre><h3 id="TODO-find-the-effective-method"><a href="#TODO-find-the-effective-method" class="headerlink" title="TODO, find the effective method"></a>TODO, find the effective method</h3><ul>
<li>If we can get the bash file name?</li>
<li>How to translate relative directory to be full directory?</li>
</ul>
<h3 id="Reference"><a href="#Reference" class="headerlink" title="Reference"></a>Reference</h3><ul>
<li><a href="http://blog.sina.com.cn/s/blog_60d6fadc01013k0k.html" target="_blank" rel="external">Difference of source , ./ , sh, bash</a></li>
</ul>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://yoursite.com/2015/09/10/how-to-export-a-specify-full-directory-by-shell-file/" data-id="ciqqpe1td00cxnmpvcer6ajbp" class="article-share-link">Partager</a>
      
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/shell/">shell</a></li></ul>

    </footer>
  </div>
  
</article>


  
    <article id="post-makefile" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2015/09/03/makefile/" class="article-date">
  <time datetime="2015-09-02T16:00:00.000Z" itemprop="datePublished">2015-09-03</time>
</a>
    
  <div class="article-category">
    <a class="article-category-link" href="/categories/program/">program</a>
  </div>

  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/2015/09/03/makefile/">makefile</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h3 id="Generate-each-source-file-to-be-one-bin-file"><a href="#Generate-each-source-file-to-be-one-bin-file" class="headerlink" title="Generate each source file to be one bin file"></a>Generate each source file to be one bin file</h3><ul>
<li><p>Makefile</p>
<pre><code>CC     = g++
CFLAGS += -g -Wall
SRC    = $(wildcard *.cc)
#OBJS   = $(SRC:.cc=.o)
BINS   = $(SRC:.cc=)
LIBS   = 

all:$(BINS)

# bin files depend on *.cc files
%:%.cc
    $(CC) $(CFLAGS) -o $@ $&lt;

.PHONY: clean
clean:
    rm -f *.o $(BINS)
</code></pre></li>
</ul>
<h3 id="Generate-all-source-files-to-be-on-bin-file"><a href="#Generate-all-source-files-to-be-on-bin-file" class="headerlink" title="Generate all source files to be on bin file"></a>Generate all source files to be on bin file</h3><ul>
<li><p>Makefile</p>
<pre><code>CC     = g++
CFLAGS += -g -Wall
SRC    = $(wildcard *.cc)
OBJS   = $(SRC:.cc=.o)
#BINS   = $(SRC:.cc=)
TARGET = test
LIBS   = 

all:$(TARGET)

# bin files depend on *.cc files
$(TARGET):$(OBJS)
    $(CC) $(CFLAGS) -o $@ $&lt;

.PHONY: clean
clean:
    rm -f *.o $(TARGET)
</code></pre></li>
</ul>
<h3 id="Auto-run-all-Makefile-in-all-sub-directory"><a href="#Auto-run-all-Makefile-in-all-sub-directory" class="headerlink" title="Auto run all Makefile in all sub-directory"></a>Auto run all Makefile in all sub-directory</h3><ul>
<li><p>Makefile</p>
<pre><code>########################################################
# Makefile
# History:
#        2013/04/17 Dennis Create
########################################################

include ./Make.defines

subdirs := $(sort $(subst /,,$(dir $(wildcard */*))))

all:
    $(foreach N,$(subdirs),make -C $(N);)

.PHONY: clean
clean:
    $(foreach N,$(subdirs),make -C $(N) clean;)
    rm -f $(CLEANFILES)
</code></pre></li>
<li><p>Make.define</p>
<pre><code># &quot;make&quot; is executed in all the subdirectories of this directory

CC = gcc
CFLAGS  = -I../lib -g -o2 -D_REENTRANT -Wall
LIBS = ../libunp.a -lpthread

LIBUNP_NAME = ../libunp.a

LIB_OBJS = error.o wrapsock.o str_echo.o writen.o wrapunix.o wraplib.o str_cli.o \
           readline.o wrapstdio.o tcp_listen.o tcp_connect.o signal.o readn.o \
           write_fd.o read_fd.o

CLEANFILES = *.o *.a tags cscope.out
</code></pre></li>
<li><p>epoll/Makefile</p>
<pre><code>CC     = gcc
CFLAGS = -Wall -g2
LIB_CPP= -lstdc++

TARGET = t1 t2 t3

all:$(TARGET)

t1: t1.c
    $(CC) $(FLAGS) -o $@ $^

t2: t2.c
    $(CC) $(FLAGS) -o $@ $^

t3: t3.cpp
    $(CC) $(FLAGS) $(LIB_CPP) -o $@ $^

.PHONY:clean
clean:
    rm -f *.o $(TARGET)
</code></pre></li>
</ul>
<h3 id="Example"><a href="#Example" class="headerlink" title="Example"></a>Example</h3><ul>
<li><p>Makefile</p>
<pre><code>###########################################################
# Makefile
#
# History:
# 2013-06-03 Dennis Create
# 2013-06-04 Dennis Make it correct and better
###########################################################

.SUFFIXES : .x .o .c .cpp .s
ROOTDIR    = $(shell pwd)

CC = g++

TARGET = cppscsi

#LIBDIR    = $(ROOTDIR)/lib
#SHARLIB:=$(shell find $(LIBDIR) -name &apos;*.so&apos;)

INCPATH = $(ROOTDIR)
INCPRG  =-I$(INCPATH) \
         -I$(INCPATH)/common \
         -I$(INCPATH)/digest \
         -I$(INCPATH)/datasegment \
         -I$(INCPATH)/login

INCDIR  = $(INCPRG)

CFLAGS += $(INCDIR)

#SOURCES:=$(shell find $(ROOTDIR) -name &apos;*.cpp&apos; -o -name &apos;*.c&apos;)
SOURCES:=$(shell find $(ROOTDIR) -maxdepth 1 -name &apos;*.cpp&apos; -o -name &apos;*.c&apos;)
CPPSRC :=$(notdir $(SOURCES))
OBJECTS:=$(CPPSRC:.cpp=.o)

# search all subdirs
#subdirs := $(sort $(subst /,,$(dir $(wildcard */*))))
subdirs := ./common \
           ./digest \
           ./data \
           ./datasegment \
           ./login

# generate subdirs object name
OBJS_OTHER_SRC := $(shell find $(subdirs) -name &apos;*.cpp&apos;)
OBJS_OTHER := $(OBJS_OTHER_SRC:.cpp=.o)

all: $(TARGET)

$(TARGET): $(OBJECTS)
    @echo &quot;**************** build subdir ****************&quot;
    $(foreach N,$(subdirs),make -C $(N);)
    @echo &quot;**************** link target ****************&quot;
    $(CC) -o $(TARGET) $(OBJECTS) $(OBJS_OTHER) $(SHARLIB) $(CFLAGS)

$(OBJECTS): %.o:%.cpp
    $(CC) -c $&lt; $(CFLAGS)

.PHONY: clean
clean:
    $(foreach N,$(subdirs),make -C $(N) clean;)
    rm -f *.o $(TARGET) 
</code></pre></li>
<li><p>login/Makefile</p>
<pre><code>###########################################################
# Makefile
#
# History:
# 2013-06-05 Dennis Create
###########################################################

CC= g++

SRC= LoginRequestParser.cpp \
     LoginResponseParser.cpp \
     ISID.cpp

FLAGS = -I../ -I../common

OBJS := $(SRC:.cpp=.o)

all: $(OBJS)

$(OBJS): %.o:%.cpp
    $(CC) $(FLAGS) -c $&lt;

.PHONY: clean
clean:
    rm -f *.o 
</code></pre></li>
</ul>
<h3 id="An-complex-example"><a href="#An-complex-example" class="headerlink" title="An complex example"></a>An complex example</h3><ul>
<li><p>Makefile</p>
<pre><code>###########################################################
# Makefile
# 
# History:
#    v1.2  2014-08-24 Dennis  Generate install script
#    v1.1  2014-07-12 Dennis  Auto generate version info
#    v1.0  2014-06-19 Dennis  Create
###########################################################

CC     = gcc
CFLAGS+= -Wall -g
INC    = -I./
SRC    = main.c \
         other_sources.c
OBJ    = $(SRC:.c=.o)
# NOTE: gcc start loading libraries from the right, 
#       so $(LIB) should be on the far right of gcc 
LIB    = -lpthread
TARGET = myapp

all: gen-version $(TARGET)

$(TARGET): $(OBJ)
    $(CC) $(CFLAGS) $(INC) -o $@ $^ $(LIB)

gen-version:
    @./update-version.sh

# Generate install script
release:
    @echo &quot;Generate release script&quot;
    @tar zcf myapp.tar.gz myapp config.conf
    @cat install.sh myapp.tar.gz &gt;myapp-install.run
    @chmod +x myapp-install.run

.PHONY:clean
clean:
    -rm -f $(TARGET) $(OBJ) myapp.tar.gz myapp-install.run
</code></pre></li>
<li><p>install.sh</p>
<pre><code>#!/bin/bash
echo &quot;&quot;
echo &quot;Self Extracting Installer&quot;
echo &quot;&quot;

export TMPDIR=`mktemp -d /tmp/selfextract.XXXXXX`

ARCHIVE=`awk &apos;/^__ARCHIVE_BELOW__/{print NR+1; exit 0;}&apos; $0`

tail -n+$ARCHIVE $0 | tar xzv -C $TMPDIR

CDIR=`pwd`
cd $TMPDIR

#./installer   # 改为压缩包中安装程序的地址

# Make sure we are root
if [ `id | sed -e &apos;s/(.*//&apos;` != &quot;uid=0&quot; ]; then
  echo &quot;Sorry, you need super user privileges to run this script.&quot;
  exit 1
fi

#UNINST=
#
# Check for and uninstall any previous version.
#
if [ -x &quot;${UNINST}&quot; ]; then
  echo &quot;Removing previous installation...&quot;
  #
fi

INSTALL_DIR=/opt/app/myapp/ 
if [ ! -d $INSTALL_DIR ]; then
    mkdir -p $INSTALL_DIR
fi
cp -f myapp $INSTALL_DIR
cp -f config.conf $INSTALL_DIR

cd $CDIR
rm -rf $TMPDIR

exit 0

__ARCHIVE_BELOW__
</code></pre></li>
<li><p>update-version.sh</p>
<pre><code>sh -c &quot;sed -i -e &apos;/__MYAPP_AUTO_VERSION__/ {
    s/=.*$/= \&quot;git commit $(git rev-parse HEAD), compiled $(date &apos;+%Y-%m-%d %H:%M&apos;)\&quot;\;/
}&apos; version.c&quot;
sh -c &quot;sed -i -e &apos;/__MYAPP_AUTO_DATE__/ {
        s/=.*$/= \&quot;$(date &apos;+%Y&apos;)\&quot;\;/
}&apos; version.c&quot;
</code></pre></li>
<li><p>version.c</p>
<pre><code>/*===============================================================
 * Copyright (C) 2014 All rights reserved.
 * 
 * 文件名称：version.h
 * 创 建 者：Matrix207
 * 创建日期：2014年07月12日
 * 描    述：
 *
 * 更新日志：
 *
 ================================================================*/
#ifndef _VERSION_H_
#define _VERSION_H_

char __MYAPP_AUTO_VERSION__[] = &quot;git commit 93785a3926fd2be190a2154b639d8eb7a83fa2e3, compiled 2014-08-24 13:08&quot;;
char __MYAPP_AUTO_DATE__[] = &quot;2014&quot;;
#endif /* _VERSION_H_ */
</code></pre></li>
</ul>
<h3 id="Another-example"><a href="#Another-example" class="headerlink" title="Another example"></a>Another example</h3><ul>
<li><p>Makefile</p>
<pre><code>#################################################################
# Copyright (C) 2014 All rights reserved.
# 
# 文件名称：Makefile
# 创 建 者：Dennis
# 创建日期：2014年12月11日
# 描    述：
#
# 更新日志：
#   v0.1  20141211  Dennis  创建
##################################################################
DATE_TIME=$(shell date &apos;+%y%m%d%H%M%S&apos;)
DATE_TIME2=$(shell date &apos;+%Y-%m-%d %H:%M&apos;)

DIR_INC = ./common
DIR_SRC = ./
DIR_BIN = ./
CC      = gcc
INC     = -I./common -I./inc
SRC     = $(wildcard ${DIR_SRC}/*.c)
COMMON  = $(wildcard ${DIR_INC}/*.c)
LIB     = -lm
#LIB     = -lpthread
CFLAGS  = -g -Wall -I${DIR_INC}

TARGET = ${DIR_BIN}/mytest

all: PREPARE_DIR gen-version $(TARGET)

$(TARGET): $(SRC) $(COMMON)
    $(CC) $(CFLAGS) $(INC) -o $@ $^ $(LIB)

PREPARE_DIR:
    mkdir -p $(DIR_BIN)

gen-version:
    ./update-version.sh

.PHONY:clean
clean:
    rm -f $(TARGET)
</code></pre></li>
</ul>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://yoursite.com/2015/09/03/makefile/" data-id="ciqqpe1ta00cunmpvbqzfbpxj" class="article-share-link">Partager</a>
      
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/makefile/">makefile</a></li></ul>

    </footer>
  </div>
  
</article>


  
    <article id="post-apache-avro-analyzed" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2015/08/25/apache-avro-analyzed/" class="article-date">
  <time datetime="2015-08-24T16:00:00.000Z" itemprop="datePublished">2015-08-25</time>
</a>
    
  <div class="article-category">
    <a class="article-category-link" href="/categories/source/">source</a>
  </div>

  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/2015/08/25/apache-avro-analyzed/">apache avro analyzed</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h4 id="analyzed-apace-avro-c-code"><a href="#analyzed-apace-avro-c-code" class="headerlink" title="analyzed apace avro c code"></a>analyzed apace avro c code</h4><pre><code>////////////////////////////////////////////////////////////
// Apache Avro c实现代码分析
// 
// By matrix207 2015-08-03 at home
// 
////////////////////////////////////////////////////////////

/////////////////////// Part 1 /////////////////////////////
文件                             功能
--------------------------------------------------------------------------
allocation.c allocation.h   一个提供申请、追加和释放内存功能的接口实现
                            参考Lua的解析器实现
array.c
avroappend.c                例子?
avrocat.c                   例子?
avro_generic_internal.h
avro.h                      include一些头文件
avromod.c                   应该是测试压缩一个schema文件的例子?
avropipe.c                  例子?
avro_private.h              一些宏,感觉没有特别用处
codec.h codec.c             编码器, 支持三种压缩算法:DEFLATE、LZMA和SNAPPY
consume-binary.c
consumer.h consumer.c       消费者???
datafile.c
datum.h datum.c             
datum_equal.c
datum_read.c
datum_size.c
datum_skip.c
datum_validate.c
datum_value.c
datum_write.c
dump.c
dump.h
encoding_binary.c
encoding.h
errors.h errors.c           错误信息，支持设置和提取功能，支持在已有的错误信息前插入新的错误信息.
generic.h generic.c         内容很多,还要继续研究????
io.h io.c                   io类型，包含文件io和内存io
map.c                       map数据操作的实现
memoize.c                   avro_memoize_t数据类型操作的实现
resolved-reader.c
resolved-writer.c
resolver.h resolver.c
schema.h schema.c
schema_equal.c
schema_specific.c
st.h st.c                   通用hash表实现
string.c                    使用wrapper buffer的方式创建一个类似string的数据avro_raw_string_t
                            这里主要实现相关操作
value.h value.c
value-hash.c                value的hash操作，功能是??
value-json.c                把二进制格式数据(datum)转化为支持UTF-8的JSON格式数据(avrocat中有使用)
value-read.c                定义方法avro_value_read, 供datafile.c使用,avro_file_writer_open用到
value-sizeof.c              定义方法avro_value_sizeof, 没有找到使用者???
value-write.c               定义方法avro_value_write,供datum_write.c和datafile.c使用
wrapped-buffer.c            buffer操作

msinttypes.h                windows平台文件
platform.h                  平台文件, 针对不同平台include不同的头文件
basics.h                    简单和复杂数据类型的枚举型定义、schema和datum类型定义、对象类型定义
                            各种宏来判断数据类型(简单和复杂类型)
data.h                      各种数据类型的结构体定义(array、Maps、Wrapped buffer、strings、Memoization
legacy.h                    为了兼容旧接口而保留的接口(新代码不会使用)
msstdint.h                  windows平台文件
refcount.h                  引用计数
schema.h                    一些函数声明而已

////////////////////////////////////////////////////////////
重点，理解这些代码, from encoding_binary.c

static int write_long(avro_writer_t writer, int64_t l)
{
    char buf[MAX_VARINT_BUF_SIZE];
    uint8_t bytes_written = 0;
    uint64_t n = (l &lt;&lt; 1) ^ (l &gt;&gt; 63);
    while (n &amp; ~0x7F) {
        buf[bytes_written++] = (char)((((uint8_t) n) &amp; 0x7F) | 0x80);
        n &gt;&gt;= 7;
    }
    buf[bytes_written++] = (char)n;
    AVRO_WRITE(writer, buf, bytes_written);
    return 0;
}
</code></pre>
      
    </div>
    <footer class="article-footer">
      <a data-url="http://yoursite.com/2015/08/25/apache-avro-analyzed/" data-id="ciqqpe1ue00dwnmpv36syr3eb" class="article-share-link">Partager</a>
      
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/c/">c</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/database/">database</a></li></ul>

    </footer>
  </div>
  
</article>


  
    <article id="post-core-dumped" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2015/08/24/core-dumped/" class="article-date">
  <time datetime="2015-08-23T16:00:00.000Z" itemprop="datePublished">2015-08-24</time>
</a>
    
  <div class="article-category">
    <a class="article-category-link" href="/categories/program/">program</a>
  </div>

  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/2015/08/24/core-dumped/">core dumped</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h3 id="What-is-coredump"><a href="#What-is-coredump" class="headerlink" title="What is coredump"></a>What is coredump</h3><h3 id="How-to-analyse-coredump"><a href="#How-to-analyse-coredump" class="headerlink" title="How to analyse coredump"></a>How to analyse coredump</h3><h3 id="Why-program-coredump"><a href="#Why-program-coredump" class="headerlink" title="Why program coredump"></a>Why program coredump</h3><ul>
<li>memory overload</li>
<li>using thread-unsafe functions on multi-thread</li>
<li>not using lock when read-write data in multi-thread</li>
<li>invalid point</li>
<li>stack overload</li>
</ul>
<h3 id="How-to-use-core-file"><a href="#How-to-use-core-file" class="headerlink" title="How to use core file"></a>How to use core file</h3><ul>
<li>allow to generate core file<ul>
<li><code>ulimit –c unlimited</code></li>
<li><code>echo /tmp/core.%e.%p &gt; /proc/sys/kernel/core_pattern</code></li>
<li><code>gcc –g core_dump_test.c -o core_dump_test</code>, must used <code>-g</code> to build.</li>
</ul>
</li>
<li>get core file<ul>
<li><code>./test</code></li>
</ul>
</li>
<li>debug<ul>
<li><code>gdb ./test /tmp/core</code></li>
<li><code>bt</code></li>
<li><code>f 3</code></li>
<li><code>p buffer</code></li>
</ul>
</li>
</ul>
<h3 id="Signal-of-core"><a href="#Signal-of-core" class="headerlink" title="Signal of core"></a>Signal of core</h3><ul>
<li><code>man 7 signal</code></li>
</ul>
<h3 id="Examples"><a href="#Examples" class="headerlink" title="Examples"></a>Examples</h3><ul>
<li><p>write data to protected memory</p>
<pre><code>#include &lt;stdio.h&gt;
int main(){
   int i=0;
   scanf(&quot;%d&quot;,i);
   printf(&quot;%d\n&quot;,i);
   return 0;
}

#include &lt;stdio.h&gt;
int main(){
   char *p;
   p = NULL;
   *p = &apos;x&apos;;
   printf(&quot;%c&quot;, *p);
   return 0;
}
</code></pre></li>
<li><p>memory overflow (array overflow, variable type different and so on)</p>
<pre><code>#include &lt;stdio.h&gt;
int main(){
    char test[1];
    printf(&quot;%c&quot;, test[1000000000]);
    return 0;
}
</code></pre></li>
</ul>
<p>Access to a not exist address</p>
<pre><code>#include &lt;stdio.h&gt;
 int main(){
      int b = 10;
      printf(&quot;%s\n&quot;, b);
      return 0;
}

#include &lt;stdio.h&gt;
#include &lt;string.h&gt;
  int main(){
     char c=&apos;c&apos;;
     int i=10;
     char buf[100];
     printf(&quot;%s&quot;, c); //试图把char型按照字符串格式输出，这里的字符会解释成整数，
                           //再解释成地址，所以原因同上面那个例子
     printf(&quot;%s&quot;, i); //试图把int型按照字符串输出
     memset(buf, 0, 100);
     sprintf(buf, &quot;%s&quot;, c);  试图把char型按照字符串格式转换
     memset(buf, 0, 100);
     sprintf(buf, &quot;%s&quot;, i);//试图把int型按照字符串转换
}
</code></pre><ul>
<li>Other, likes:<ul>
<li>Initialization when defined point, check point before using.</li>
<li>Careful array index</li>
<li>check if success when do <code>pthread_create</code>, if fail and do <code>pthread_join</code> for<br>this thread will occur segment fault</li>
</ul>
</li>
</ul>
<h3 id="Auto-start-gdb-when-core-occur"><a href="#Auto-start-gdb-when-core-occur" class="headerlink" title="Auto start gdb when core occur"></a>Auto start gdb when core occur</h3><pre><code>#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;signal.h&gt;
#include &lt;string.h&gt;
#include &lt;sys/types.h&gt;
#include &lt;unistd.h&gt;

void dump(int signo)
{
    char buf[1024];
    char cmd[1024];
    FILE *fh;

    snprintf(buf, sizeof(buf), &quot;/proc/%d/cmdline&quot;, getpid());
    if(!(fh = fopen(buf, &quot;r&quot;)))
        exit(0);
    if(!fgets(buf, sizeof(buf), fh))
        exit(0);
    fclose(fh);
    if(buf[strlen(buf) - 1] == &apos;\n&apos;)
        buf[strlen(buf) - 1] = &apos;\0&apos;;
    snprintf(cmd, sizeof(cmd), &quot;gdb %s %d&quot;, buf, getpid());
    system(cmd);

    exit(0);
}

void dummy_function (void)
{
    unsigned char *ptr = 0x00;
    *ptr = 0x00;
}

int main (void)
{
    signal(SIGSEGV, &amp;dump);
    dummy_function ();

    return 0;
}
</code></pre><h3 id="Reference"><a href="#Reference" class="headerlink" title="Reference"></a>Reference</h3><ul>
<li><a href="http://blog.csdn.net/newnewman80/article/details/8173770" target="_blank" rel="external">coredump简介与coredump原因总结</a></li>
<li><a href="http://www.cnblogs.com/hello--the-world/archive/2012/05/31/2528326.html" target="_blank" rel="external">C/C++中的段错误（Segmentation fault）</a></li>
<li><a href="http://blog.csdn.net/freshman_fantom_ywj/article/details/6434074" target="_blank" rel="external">段错误bug的调试</a></li>
</ul>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://yoursite.com/2015/08/24/core-dumped/" data-id="ciqqpe1t800crnmpvmltsbv1x" class="article-share-link">Partager</a>
      
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/debug/">debug</a></li></ul>

    </footer>
  </div>
  
</article>


  
    <article id="post-difference-between-stack-and-heap" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2015/07/17/difference-between-stack-and-heap/" class="article-date">
  <time datetime="2015-07-16T16:00:00.000Z" itemprop="datePublished">2015-07-17</time>
</a>
    
  <div class="article-category">
    <a class="article-category-link" href="/categories/program/">program</a>
  </div>

  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/2015/07/17/difference-between-stack-and-heap/">difference between stack and heap</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h3 id="Difference"><a href="#Difference" class="headerlink" title="Difference"></a>Difference</h3><ul>
<li>stack <ul>
<li>allocate memory on stack by operate system</li>
<li>Have limit size, and less than 1MB always</li>
</ul>
</li>
<li>heap <ul>
<li>allocate memeory on heap</li>
<li>using <code>malloc</code> or <code>new</code> to allocate memory</li>
<li>user and defined the size, and the limit depend on virtual memory size</li>
<li>prone to memory fragments</li>
</ul>
</li>
</ul>
<h3 id="What-is-memory-fragments"><a href="#What-is-memory-fragments" class="headerlink" title="What is memory fragments"></a>What is memory fragments</h3><ul>
<li>Internal fragmentation <ul>
<li>memory allocation provided memory to program in chunks divisible by 4, 8 or 16</li>
<li>if application request 23 bytes, it actually get a chunk of 32 bytes. </li>
<li>Really? How to prove it? And what happen if I using memory not belong to me?</li>
</ul>
</li>
<li>External fragmentation <ul>
<li>cause by <code>free</code> called</li>
<li>An example, first, you allocate 9 bytes memory, then allocate another 5 bytes,<br>and later you free the first 9 bytes, but now, you want to allocate 10 bytes,<br>this time the first 9 bytes memory can’t be used, because it is not enough.<br>Allocation must using continues memory, so it would allocate another 10 bytes<br>behind the 5 bytes position. Now the first block memory is memory fragments.</li>
</ul>
</li>
</ul>
<h3 id="How-to-avoid-memory-fragments"><a href="#How-to-avoid-memory-fragments" class="headerlink" title="How to avoid memory fragments"></a>How to avoid memory fragments</h3><h3 id="Why-memory-overflow-but-not-error-occur"><a href="#Why-memory-overflow-but-not-error-occur" class="headerlink" title="Why memory overflow but not error occur?"></a>Why memory overflow but not error occur?</h3><ul>
<li><p>sample code</p>
<pre><code>#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;string.h&gt;

void main()
{
    // allocate 13 bytes memory on heap
    char* p = (char*)malloc(13);
    char* c_12 = &quot;012345678912&quot;;
    char* c_15 = &quot;012345678912345&quot;;
    char* c_19 = &quot;0123456789123456789&quot;;
    char* c_99 = &quot;aaaaaaaaaaaaaaaaaaaa&quot;
    &quot;aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa&quot;
    &quot;aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa&quot;
    &quot;aaaaaaaaaaaaa&quot;;

    printf(&quot;do copy 12 bytes to p\n&quot;);
    strncpy(p, c_12, strlen(c_12)+1);
    p[12] = &apos;\0&apos;; printf(&quot;p=%s\n&quot;, p);

    printf(&quot;do copy 15 bytes to p\n&quot;);
    strncpy(p, c_15, strlen(c_15)+1);
    p[16] = &apos;\0&apos;; printf(&quot;p=%s\n&quot;, p);

    printf(&quot;do copy 19 bytes to p\n&quot;);
    strncpy(p, c_19, strlen(c_19)+1);
    p[20] = &apos;\0&apos;; printf(&quot;p=%s\n&quot;, p);

    printf(&quot;do copy 99 bytes to p\n&quot;);
    strncpy(p, c_99, strlen(c_99)+1);
    p[100] = &apos;\0&apos;; printf(&quot;p=%s\n&quot;, p);

    printf(&quot;Hello world\n&quot;);
}
</code></pre></li>
</ul>
<h3 id="Reference"><a href="#Reference" class="headerlink" title="Reference"></a>Reference</h3><ul>
<li><a href="http://blog.csdn.net/xuzhonghai/article/details/7285821" target="_blank" rel="external">内存碎片</a></li>
<li><a href="https://en.wikipedia.org/wiki/Fragmentation_(computing" target="_blank" rel="external">Fragmentation</a>)</li>
</ul>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://yoursite.com/2015/07/17/difference-between-stack-and-heap/" data-id="ciqqpe1t400conmpvq1mlt3jm" class="article-share-link">Partager</a>
      
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/memory/">memory</a></li></ul>

    </footer>
  </div>
  
</article>


  
    <article id="post-key-technology-for-database" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2015/07/12/key-technology-for-database/" class="article-date">
  <time datetime="2015-07-11T16:00:00.000Z" itemprop="datePublished">2015-07-12</time>
</a>
    
  <div class="article-category">
    <a class="article-category-link" href="/categories/database/">database</a>
  </div>

  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/2015/07/12/key-technology-for-database/">key technology for database</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h3 id="Introduce"><a href="#Introduce" class="headerlink" title="Introduce"></a>Introduce</h3><h3 id="Hash"><a href="#Hash" class="headerlink" title="Hash"></a>Hash</h3><h3 id="BTree"><a href="#BTree" class="headerlink" title="BTree"></a>BTree</h3><h3 id="B-Tree"><a href="#B-Tree" class="headerlink" title="B+Tree"></a>B+Tree</h3><h3 id="Reference"><a href="#Reference" class="headerlink" title="Reference"></a>Reference</h3><ul>
<li>Add wikipedia of Hash key</li>
<li>Add wikipedia of BTree key</li>
<li>Add wikipedia of B+Tree key</li>
</ul>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://yoursite.com/2015/07/12/key-technology-for-database/" data-id="ciqqpe1sw00cinmpv3lfrtve5" class="article-share-link">Partager</a>
      
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/database/">database</a></li></ul>

    </footer>
  </div>
  
</article>


  
    <article id="post-schema-data-model" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2015/07/12/schema-data-model/" class="article-date">
  <time datetime="2015-07-11T16:00:00.000Z" itemprop="datePublished">2015-07-12</time>
</a>
    
  <div class="article-category">
    <a class="article-category-link" href="/categories/database/">database</a>
  </div>

  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/2015/07/12/schema-data-model/">schema data model</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h3 id="Data-model"><a href="#Data-model" class="headerlink" title="Data model"></a>Data model</h3><h3 id="Why-need-it"><a href="#Why-need-it" class="headerlink" title="Why need it"></a>Why need it</h3><h3 id="Schema-Node"><a href="#Schema-Node" class="headerlink" title="Schema Node"></a>Schema Node</h3><ul>
<li>Define<ul>
<li>R : root node (record node)</li>
<li>S : single node (child node, subschema)</li>
<li>A : array node (child node, subschema)</li>
</ul>
</li>
<li>Example<ul>
<li>R, only root node</li>
<li>R -&gt; S1, only a singal node under root</li>
<li>R -&gt; A1, only an array node under root</li>
<li>R -&gt; A1 -&gt; A2</li>
<li>R -&gt; A1 -&gt; S1</li>
<li>R -&gt; S1 -&gt; A1</li>
<li>R -&gt; S1 -&gt; S2</li>
<li>R -&gt; S1 -&gt; A1 -&gt; S2</li>
<li>R -&gt; A1 -&gt; S1 -&gt; A2</li>
</ul>
</li>
<li>How to find the last node info by index of node?<ul>
<li>step 0, set root node as parent node</li>
<li>step 1, use parent node to find array index</li>
<li>step 2, found array node, set this node to new parent node, go to step 1</li>
<li>step 3, use the parent node to find the last node</li>
<li>step 4, do some operations for the node<ul>
<li>set value to fields and insert. (Using for add a new object)</li>
</ul>
</li>
<li>Notices<ul>
<li>only root node</li>
</ul>
</li>
</ul>
</li>
<li>How to create a key</li>
<li>How to write object</li>
<li>How to read object</li>
<li>How to update object</li>
<li>What is difference between full and delta object</li>
<li>Since there are read and write interfaces, why not insert and delete</li>
</ul>
<h3 id="Reference"><a href="#Reference" class="headerlink" title="Reference"></a>Reference</h3>
      
    </div>
    <footer class="article-footer">
      <a data-url="http://yoursite.com/2015/07/12/schema-data-model/" data-id="ciqqpe1t100clnmpvv5tizz2e" class="article-share-link">Partager</a>
      
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/database/">database</a></li></ul>

    </footer>
  </div>
  
</article>


  
    <article id="post-what-learn-from-distributed-database" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2015/07/06/what-learn-from-distributed-database/" class="article-date">
  <time datetime="2015-07-05T16:00:00.000Z" itemprop="datePublished">2015-07-06</time>
</a>
    
  <div class="article-category">
    <a class="article-category-link" href="/categories/database/">database</a>
  </div>

  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/2015/07/06/what-learn-from-distributed-database/">What learn from distributed database</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h3 id="What-are-the-distributed-database"><a href="#What-are-the-distributed-database" class="headerlink" title="What are the distributed database"></a>What are the distributed database</h3><p>A distributed database include features:  </p>
<ul>
<li>Data model</li>
<li>SQL Engine</li>
<li>RPC</li>
<li>Backup and restore</li>
<li>Transaction</li>
<li>Common <ul>
<li>log</li>
<li>error</li>
</ul>
</li>
</ul>
<h3 id="Reference"><a href="#Reference" class="headerlink" title="Reference"></a>Reference</h3>
      
    </div>
    <footer class="article-footer">
      <a data-url="http://yoursite.com/2015/07/06/what-learn-from-distributed-database/" data-id="ciqqpe1st00cfnmpvm3zk80qm" class="article-share-link">Partager</a>
      
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/database/">database</a></li></ul>

    </footer>
  </div>
  
</article>


  
    <article id="post-how-source-code-turn-to-be-an-executable-program" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2015/07/05/how-source-code-turn-to-be-an-executable-program/" class="article-date">
  <time datetime="2015-07-04T16:00:00.000Z" itemprop="datePublished">2015-07-05</time>
</a>
    
  <div class="article-category">
    <a class="article-category-link" href="/categories/language/">language</a>
  </div>

  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/2015/07/05/how-source-code-turn-to-be-an-executable-program/">How source code turn to be an executable program</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h3 id="What-is-an-executable-program"><a href="#What-is-an-executable-program" class="headerlink" title="What is an executable program"></a>What is an executable program</h3><ul>
<li>On linux, the format of executable program is ELF (<code>Executable and Linking Format</code>)</li>
<li>members of executable program<ul>
<li>text segment</li>
<li>data segment</li>
<li>bss segment</li>
</ul>
</li>
</ul>
<h3 id="How-source-code-be-compiled"><a href="#How-source-code-be-compiled" class="headerlink" title="How source code be compiled"></a>How source code be compiled</h3><h3 id="Relation-of-source-code-object-file-library-file-bin-file"><a href="#Relation-of-source-code-object-file-library-file-bin-file" class="headerlink" title="Relation of source code, object file, library file, bin file"></a>Relation of source code, object file, library file, bin file</h3><h3 id="How-bin-file-to-load-library"><a href="#How-bin-file-to-load-library" class="headerlink" title="How bin file to load library"></a>How bin file to load library</h3><ul>
<li>dynamic library</li>
<li>static library</li>
</ul>
<h3 id="Example"><a href="#Example" class="headerlink" title="Example"></a>Example</h3><ul>
<li><p>Hello world, a.c</p>
<pre><code>#include &lt;stdio.h&gt;
int main()
{
    printf (&quot;Hello world\n&quot;);
}
</code></pre></li>
<li><p>compile</p>
<pre><code>[dennis@localhost ~]$ gcc a.c
[dennis@localhost ~]$ objdump -f a.out 

a.out:     file format elf64-x86-64
architecture: i386:x86-64, flags 0x00000112:
EXEC_P, HAS_SYMS, D_PAGED
start address 0x0000000000400440
[dennis@localhost ~]$ file a.out
a.out: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=7396e4d6e7100d1536548d05ba91a67255bf9592, not stripped
[dennis@localhost ~]$ size a.out
   text       data        bss        dec        hex    filename
   1226        548          4       1778        6f2    a.out
[dennis@localhost ~]$ readelf -h a.out
ELF Header:
  Magic:   7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 
  Class:                             ELF64
  Data:                              2&apos;s complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              EXEC (Executable file)
  Machine:                           Advanced Micro Devices X86-64
  Version:                           0x1
  Entry point address:               0x400440
  Start of program headers:          64 (bytes into file)
  Start of section headers:          4504 (bytes into file)
  Flags:                             0x0
  Size of this header:               64 (bytes)
  Size of program headers:           56 (bytes)
  Number of program headers:         9
  Size of section headers:           64 (bytes)
  Number of section headers:         30
  Section header string table index: 27
[dennis@localhost ~]$ readelf -S a.out
</code></pre></li>
</ul>
<h3 id="Reference"><a href="#Reference" class="headerlink" title="Reference"></a>Reference</h3><ul>
<li><a href="http://bbs.pediy.com/showthread.php?t=81284.html" target="_blank" rel="external">linux可执行文件格式</a></li>
<li><a href="http://blog.csdn.net/topasstem8/article/details/38730971" target="_blank" rel="external">Linux下可执行文件格式详解</a></li>
</ul>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://yoursite.com/2015/07/05/how-source-code-turn-to-be-an-executable-program/" data-id="ciqqpe1sr00ccnmpvkx3va7iv" class="article-share-link">Partager</a>
      
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/c/">c++</a></li></ul>

    </footer>
  </div>
  
</article>


  
    <article id="post-ramcloud" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2015/06/06/ramcloud/" class="article-date">
  <time datetime="2015-06-05T16:00:00.000Z" itemprop="datePublished">2015-06-06</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
    <div class="article-entry" itemprop="articleBody">
      
        <hr>
<p>layout: post<br>title: “ramcloud”<br>description: “”<br>category: database</p>
<h2 id="tags-database"><a href="#tags-database" class="headerlink" title="tags: [database]"></a>tags: [database]</h2><h4 id="what-is-ramcloud"><a href="#what-is-ramcloud" class="headerlink" title="what is ramcloud"></a>what is ramcloud</h4><ul>
<li>ramcloud<ul>
<li><a href="https://ramcloud.atlassian.net/wiki/display/RAM/RAMCloud;jsessionid=D118195965ABC5BF8B90B34EC242B5CE" target="_blank" rel="external">ramcloud</a></li>
<li><a href="http://blog.csdn.net/anzhsoft/article/details/21830991" target="_blank" rel="external">RAMCloud：内存云存储的内存分配机制</a></li>
</ul>
</li>
</ul>
<h4 id="compile-source-code"><a href="#compile-source-code" class="headerlink" title="compile source code"></a>compile source code</h4><ul>
<li><p>install dependency library</p>
<ul>
<li>yum install boost-devel protobuf-devel pcre-devel gtest-devel zookeeper-devel</li>
</ul>
</li>
<li><p>install dependency library</p>
<ul>
<li><p>2015-11-08 </p>
<ul>
<li>update: pull the latest code and do <code>yum install openssl-devel</code></li>
<li><p>6f18e4dfb36ae370f21b39e7f4a4b346c224f469</p>
<p>  [dennis@localhost RAMCloud-master]$ pwd<br>  /home/dennis/work/RAMCloud-master<br>  [dennis@localhost RAMCloud-master]$ make</p>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<h4 id="source-code"><a href="#source-code" class="headerlink" title="source code"></a>source code</h4><ul>
<li>Client, CRamCloud.{h,cc}</li>
<li><p>getTableId test from RamCloudTest.cc</p>
<pre><code>TEST_F(RamCloudTest, getTableId) {
    string message(&quot;no exception&quot;);
    try {
        ramcloud-&gt;getTableId(&quot;bogusTable&quot;);
    }
    catch (ClientException&amp; e) {
        message = e.toSymbol();
    }
    EXPECT_EQ(&quot;STATUS_TABLE_DOESNT_EXIST&quot;, message);
    uint64_t id = ramcloud-&gt;getTableId(&quot;table2&quot;);
    EXPECT_EQ(2UL, id);
}

using `ramcloud-&gt;getTableId(&quot;bogusTable&quot;);` to get an id from a not exist table,  
and expect return &quot;STATUS_TABLE_DOESNT_EXIST&quot;

from code `tableId2 = ramcloud-&gt;createTable(&quot;table2&quot;);`, expect id of table2 is 2UL
</code></pre></li>
<li><p>code of table operation: create, drop, getTableId, relax files: TableManager.cc</p>
</li>
<li><p>object serialization and deserialization</p>
<pre><code>+---------------+--------+---------------------------+----------+----------+
| Object Header | # keys | Cumulative Key Lengths .. | Keys ... | Data ... |
+---------------+--------+---------------------------+----------+----------+
               &lt;--------------------- keysAndValue -----------------------&gt;

- `Object Header` include checksum, timestamp, version, tableID
- `keys` is keycount, the number of keys in an object 
- `CumulativeKeyLength` is KeyLength
</code></pre></li>
</ul>
<h4 id="reference"><a href="#reference" class="headerlink" title="reference"></a>reference</h4><ul>
<li><a href="https://ramcloud.atlassian.net/wiki/display/RAM/General+Information+for+Developers" target="_blank" rel="external">General Information for Developers</a></li>
<li><a href="http://fumin.hustbackup.cn/?p=1104&amp;utm_source=tuicool" target="_blank" rel="external">RAMCloud 小结</a></li>
<li><a href="http://blog.csdn.net/anzhsoft/article/details/21830991" target="_blank" rel="external">RAMCloud：内存云存储的内存分配机制</a></li>
<li><a href="http://www.csdn.net/article/2011-08-01/302490" target="_blank" rel="external">大规模存储的未来——内存云</a></li>
<li><a href="http://web.stanford.edu/~ouster/cgi-bin/papers/ramcloud.pdf" target="_blank" rel="external">The Case for RAMClouds: Scalable High-Performance Storage Entirely in DRAM</a></li>
<li><a href="http://web.stanford.edu/~ouster/cgi-bin/papers/RumblePhd.pdf" target="_blank" rel="external">MEMORY AND OBJECT MANAGEMENT IN RAMCLOUD</a></li>
</ul>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://yoursite.com/2015/06/06/ramcloud/" data-id="ciqqpe1sp00cbnmpv3gyum44t" class="article-share-link">Partager</a>
      
      
    </footer>
  </div>
  
</article>


  


  <nav id="page-nav">
    <a class="extend prev" rel="prev" href="/page/3/">&laquo; __('prev')</a><a class="page-number" href="/">1</a><a class="page-number" href="/page/2/">2</a><a class="page-number" href="/page/3/">3</a><span class="page-number current">4</span><a class="page-number" href="/page/5/">5</a><a class="page-number" href="/page/6/">6</a><span class="space">&hellip;</span><a class="page-number" href="/page/18/">18</a><a class="extend next" rel="next" href="/page/5/">__('next') &raquo;</a>
  </nav>
</section>
        
          <aside id="sidebar">
  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Catégories</h3>
    <div class="widget">
      <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/categories/blog/">blog</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/database/">database</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/english/">english</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/kernel/">kernel</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/language/">language</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/linux/">linux</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/math/">math</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/network/">network</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/others/">others</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/person/">person</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/program/">program</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/source/">source</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/storage/">storage</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/tools/">tools</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/windows/">windows</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Mot-clés</h3>
    <div class="widget">
      <ul class="tag-list"><li class="tag-list-item"><a class="tag-list-link" href="/tags/FAQ/">FAQ</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/IRC/">IRC</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Translation/">Translation</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/android/">android</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/api/">api</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/assembly/">assembly</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/awk/">awk</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/batch/">batch</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/blog/">blog</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/book/">book</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/c/">c</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/c/">c++</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/cache/">cache</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/crash/">crash</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/database/">database</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/debug/">debug</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/dot/">dot</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/driver/">driver</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/emacs/">emacs</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/exploit/">exploit</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/file-system/">file system</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/filesystem/">filesystem</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/flowchart/">flowchart</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/gcc/">gcc</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/git/">git</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/google/">google</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/graphviz/">graphviz</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/hexo/">hexo</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/hosts/">hosts</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/iscsi/">iscsi</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/java/">java</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/javascript/">javascript</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/job/">job</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/json/">json</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/kernel/">kernel</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/linux/">linux</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/lisp/">lisp</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/lua/">lua</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/makefile/">makefile</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/malloc/">malloc</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/math/">math</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/maxima/">maxima</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/memory/">memory</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/memory-overflow/">memory overflow</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/mtrace/">mtrace</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/netdisk/">netdisk</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/network/">network</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/others/">others</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/pandoc/">pandoc</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/performance/">performance</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/person/">person</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/protobuf/">protobuf</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/python/">python</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/rsync/">rsync</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/sed/">sed</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/shell/">shell</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/skype/">skype</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/sms/">sms</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/source/">source</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/ssh/">ssh</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/stack/">stack</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/storage/">storage</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/study/">study</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/svn/">svn</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/sync/">sync</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/test/">test</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/time/">time</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/tools/">tools</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/valgrind/">valgrind</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/vi/">vi</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/vim/">vim</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/virtual/">virtual</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/wget/">wget</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/windows/">windows</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/wireshark/">wireshark</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/write/">write</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/xml/">xml</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Nuage de mot-clés</h3>
    <div class="widget tagcloud">
      <a href="/tags/FAQ/" style="font-size: 10px;">FAQ</a> <a href="/tags/IRC/" style="font-size: 10px;">IRC</a> <a href="/tags/Translation/" style="font-size: 13px;">Translation</a> <a href="/tags/android/" style="font-size: 10px;">android</a> <a href="/tags/api/" style="font-size: 10px;">api</a> <a href="/tags/assembly/" style="font-size: 10px;">assembly</a> <a href="/tags/awk/" style="font-size: 11px;">awk</a> <a href="/tags/batch/" style="font-size: 14px;">batch</a> <a href="/tags/blog/" style="font-size: 10px;">blog</a> <a href="/tags/book/" style="font-size: 10px;">book</a> <a href="/tags/c/" style="font-size: 16px;">c</a> <a href="/tags/c/" style="font-size: 19px;">c++</a> <a href="/tags/cache/" style="font-size: 10px;">cache</a> <a href="/tags/crash/" style="font-size: 10px;">crash</a> <a href="/tags/database/" style="font-size: 17px;">database</a> <a href="/tags/debug/" style="font-size: 12px;">debug</a> <a href="/tags/dot/" style="font-size: 10px;">dot</a> <a href="/tags/driver/" style="font-size: 10px;">driver</a> <a href="/tags/emacs/" style="font-size: 11px;">emacs</a> <a href="/tags/exploit/" style="font-size: 10px;">exploit</a> <a href="/tags/file-system/" style="font-size: 10px;">file system</a> <a href="/tags/filesystem/" style="font-size: 12px;">filesystem</a> <a href="/tags/flowchart/" style="font-size: 10px;">flowchart</a> <a href="/tags/gcc/" style="font-size: 10px;">gcc</a> <a href="/tags/git/" style="font-size: 12px;">git</a> <a href="/tags/google/" style="font-size: 11px;">google</a> <a href="/tags/graphviz/" style="font-size: 11px;">graphviz</a> <a href="/tags/hexo/" style="font-size: 10px;">hexo</a> <a href="/tags/hosts/" style="font-size: 10px;">hosts</a> <a href="/tags/iscsi/" style="font-size: 14px;">iscsi</a> <a href="/tags/java/" style="font-size: 10px;">java</a> <a href="/tags/javascript/" style="font-size: 10px;">javascript</a> <a href="/tags/job/" style="font-size: 10px;">job</a> <a href="/tags/json/" style="font-size: 10px;">json</a> <a href="/tags/kernel/" style="font-size: 14px;">kernel</a> <a href="/tags/linux/" style="font-size: 14px;">linux</a> <a href="/tags/lisp/" style="font-size: 10px;">lisp</a> <a href="/tags/lua/" style="font-size: 10px;">lua</a> <a href="/tags/makefile/" style="font-size: 10px;">makefile</a> <a href="/tags/malloc/" style="font-size: 10px;">malloc</a> <a href="/tags/math/" style="font-size: 11px;">math</a> <a href="/tags/maxima/" style="font-size: 10px;">maxima</a> <a href="/tags/memory/" style="font-size: 11px;">memory</a> <a href="/tags/memory-overflow/" style="font-size: 10px;">memory overflow</a> <a href="/tags/mtrace/" style="font-size: 10px;">mtrace</a> <a href="/tags/netdisk/" style="font-size: 10px;">netdisk</a> <a href="/tags/network/" style="font-size: 20px;">network</a> <a href="/tags/others/" style="font-size: 18px;">others</a> <a href="/tags/pandoc/" style="font-size: 10px;">pandoc</a> <a href="/tags/performance/" style="font-size: 16px;">performance</a> <a href="/tags/person/" style="font-size: 11px;">person</a> <a href="/tags/protobuf/" style="font-size: 11px;">protobuf</a> <a href="/tags/python/" style="font-size: 10px;">python</a> <a href="/tags/rsync/" style="font-size: 10px;">rsync</a> <a href="/tags/sed/" style="font-size: 11px;">sed</a> <a href="/tags/shell/" style="font-size: 15px;">shell</a> <a href="/tags/skype/" style="font-size: 11px;">skype</a> <a href="/tags/sms/" style="font-size: 10px;">sms</a> <a href="/tags/source/" style="font-size: 11px;">source</a> <a href="/tags/ssh/" style="font-size: 10px;">ssh</a> <a href="/tags/stack/" style="font-size: 10px;">stack</a> <a href="/tags/storage/" style="font-size: 15px;">storage</a> <a href="/tags/study/" style="font-size: 10px;">study</a> <a href="/tags/svn/" style="font-size: 11px;">svn</a> <a href="/tags/sync/" style="font-size: 10px;">sync</a> <a href="/tags/test/" style="font-size: 11px;">test</a> <a href="/tags/time/" style="font-size: 10px;">time</a> <a href="/tags/tools/" style="font-size: 16px;">tools</a> <a href="/tags/valgrind/" style="font-size: 10px;">valgrind</a> <a href="/tags/vi/" style="font-size: 10px;">vi</a> <a href="/tags/vim/" style="font-size: 14px;">vim</a> <a href="/tags/virtual/" style="font-size: 11px;">virtual</a> <a href="/tags/wget/" style="font-size: 10px;">wget</a> <a href="/tags/windows/" style="font-size: 11px;">windows</a> <a href="/tags/wireshark/" style="font-size: 10px;">wireshark</a> <a href="/tags/write/" style="font-size: 13px;">write</a> <a href="/tags/xml/" style="font-size: 10px;">xml</a>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Archives</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/07/">July 2016</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/04/">April 2016</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/03/">March 2016</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/02/">February 2016</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/01/">January 2016</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/11/">November 2015</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/10/">October 2015</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/09/">September 2015</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/08/">August 2015</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/07/">July 2015</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/06/">June 2015</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/03/">March 2015</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/02/">February 2015</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/01/">January 2015</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2014/12/">December 2014</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2014/11/">November 2014</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2014/09/">September 2014</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2014/08/">August 2014</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2014/07/">July 2014</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2014/06/">June 2014</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2014/05/">May 2014</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2014/04/">April 2014</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2014/03/">March 2014</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2013/11/">November 2013</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2013/10/">October 2013</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2013/09/">September 2013</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2013/08/">August 2013</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2013/07/">July 2013</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2013/06/">June 2013</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2013/05/">May 2013</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2013/04/">April 2013</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2013/03/">March 2013</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2013/02/">February 2013</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2013/01/">January 2013</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2012/12/">December 2012</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2012/09/">September 2012</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Articles récents</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/2016/07/17/how-to-implement-malloc/">如何实现一个malloc</a>
          </li>
        
          <li>
            <a href="/2016/07/17/study-grep-more/">grep工作原理</a>
          </li>
        
          <li>
            <a href="/2016/07/17/2016-04-13-malloc/">malloc</a>
          </li>
        
          <li>
            <a href="/2016/04/27/include-what-you-use/">使用IWYU整理头文件引用</a>
          </li>
        
          <li>
            <a href="/2016/04/24/understand-gcc-assembly-output/">understand gcc assembly output</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      &copy; 2016 Matrix207<br>
      Propulsé by <a href="http://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>
    </div>
    <nav id="mobile-nav">
  
    <a href="/" class="mobile-nav-link">Home</a>
  
    <a href="/archives" class="mobile-nav-link">Archives</a>
  
</nav>
    

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>


  <link rel="stylesheet" href="/fancybox/jquery.fancybox.css">
  <script src="/fancybox/jquery.fancybox.pack.js"></script>


<script src="/js/script.js"></script>

  </div>
</body>
</html>